<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class can_register_model extends CI_Model
{
	public function __construct(){
		parent::__construct();
		
	}
	public function login($user_name,$password,$status)
	{
		$this->db->where('user_name',$user_name);
		$this->db->where('password',$password);
		$this->db->where('status',$status);
		$query = $this->db->get('candidate');
		if($query->num_rows()>0)
		{
			foreach($query->result() as $rows)
			{
				// add all data to session
				$newdata = array(
					'user_id' => $rows->id,
					'user_name' => $rows->user_name,
					'email' => $rows->email,
					'logged_in' => true
				);
			}
			$this->session->set_userdata($newdata);
			return true;
		}else{
			
		return false;
		}
		
	}
	// get resume
	public function get_resume($email)
	{
		$this->db->select('*');
		$this->db->from('candidate');
		$this->db->where('email',$email);
		$query = $this->db->get();
		$result = $query->result();
		
		return $result;
	}
	
	// check user exist
	public function check_user_exist($usr)
	{
		$this->db->where('user_name',$usr);
		$query = $this->db->get('candidate');
		if($query->num_rows()>0)
		{
			return true;
		}else{
			return false;
		}
		
	}
	
	// check user
	public function check_user()
	{
		$usr=$this->input->post('name');
        $result=$this->user_model->check_user_exist($usr);
        if($result)
        {
			echo "false";
			
        }
        else{
			
			echo "true";
        }
	}
	
	public function can_save()
	{
		// create array to get data from index
			$data = array(
				'first_name' => $this->input->post('firstname'),
				'last_name' => $this->input->post('lastname'),
				'nick_name' => $this->input->post('nickname'),
				'user_name' => $this->input->post('username'),
				'password' => md5($this->input->post('password')),
				'confirmpwd' => md5($this->input->post('confirmpwd')),
				'email' => $this->input->post('email'),
				'veryfies_code' => $this->input->post('veryfies_code'),
				'date_created' => date('Y-m-d'),
				'status' => 1
			);
			
			$this->db->insert('candidate',$data);
	}
	
	// update candidate
	public function can_update($id,$data)
	{
		$this->db->where('id',$id);
		$this->db->update('candidate',$data);
	}
}


?>